//
// Created by Semir on 2020/6/3.
//

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int getStartIndex(vector<int>& arr, int oldIndex) {
    int newIndex = -1;
    for (int i : arr) {
        if (i > oldIndex) {
            if (newIndex < 0) {
                newIndex = i;
            } else if (i < newIndex) {
                newIndex = i;
            }
        }
    }
    return newIndex;
}

int longestSubStringWithoutDuplication(string str) {
    if (str.length() == 0) {
        return 0;
    }
    int startIndex = -1;
    int maxLen = 0;
    vector<int> arr(26, -1);
    for (int i = 0; i < str.length(); i++) {
        int cur = str[i] - 'a';
        if (arr[cur] >= startIndex) {
            arr[cur] = i;
            startIndex = getStartIndex(arr, startIndex);
        } else {
            arr[cur] = i;
        }
        maxLen = max(arr[cur] - startIndex + 1, maxLen);
    }
    return maxLen;
}

int main() {
    int res = longestSubStringWithoutDuplication("");
    cout << res << endl;
    return 0;
}